<?php
/**
 * Klasse für Grundeinstellungen
 */
class Model_Settings extends Zend_Db_Table_Abstract
{
    /** Table name */
    protected $_name = 'settings';
	/** Primary Key */
    protected $_primary = 'sid';
    
	public function getAll($where = null, $order = null, $count = null, $offset = null)
	{
		return $this->fetchAll($where, $order, $count, $offset);
	}
    
    public function getValueByName($s_name) {
    	
    	$where = $this->select()->where('s_name = ?', $s_name);
    	$setting = $this->fetchAll($where, $order, $count, $offset)->toArray();
    	return $setting[0]['s_value'];
    	
    }
    
	public function increaseInvoiceNumber() {
    	
		//Relevante Einstellung hier ist 'current_invoice_number'
		$s_name = "current_invoice_number";
		
		$where = $this->select()->where('s_name = ?', $s_name);
    	$setting = $this->fetchAll($where, $order, $count, $offset)->toArray();
    	$invoice_number = (int) $setting[0]['s_value'];
		
    	//die($where."     ".$invoice_number);
    	
		$data['s_value'] = $invoice_number + 1;
    	
		$rows_updated = $this->update($data, $this->getAdapter()->quoteInto('s_name = ?', $s_name));
    	return $rows_updated;
    	
    }
	
};

?>